package jmvm.schemes;


import java.awt.Point;
import java.util.ArrayList;

import jmvm.components.*;
import jmvm.gui.GuiLine;
import jmvm.gui.GuiScheme;



public class Intr2 {
	
	public static NOT not_printr;
	
	public static AND AND1, AND2, AND3, AND4, AND5, AND6, AND7, ANDprintr;
	public static OR ORimrprintr;
	public static CD CDintr;
	public static CMP CMPintr;
	
	////////////
	//////////// Grafika
	////////////
	
	public static GuiScheme gui;

	public static GuiScheme getGui() {
		return gui;
	}
	
	public static void gui() {

		GuiLine line; // Pomocna promenljiva
		gui = new GuiScheme("jmvm/jmvm/images/intr2.png");
		
		ArrayList<ArrayList<Point>> sections;
		ArrayList<Point> points;
		
		// 
		// 
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(98,10));
		points.add(new Point(401,10));
		points.add(new Point(401,143));
		sections.add(points);
		line=new GuiLine(sections,Intr1.IMR1());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(98,31));
		points.add(new Point(366,31));
		points.add(new Point(366,143));
		sections.add(points);
		line=new GuiLine(sections,Intr1.IMR2());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(98,51));
		points.add(new Point(330,51));
		points.add(new Point(331,143));
		sections.add(points);
		line=new GuiLine(sections,Intr1.IMR3());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(98,72));
		points.add(new Point(295,72));
		points.add(new Point(295,143));
		sections.add(points);
		line=new GuiLine(sections,Intr1.IMR4());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(98,93));
		points.add(new Point(260,93));
		points.add(new Point(260,143));
		sections.add(points);
		line=new GuiLine(sections,Intr1.IMR5());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(98,113));
		points.add(new Point(224,113));
		points.add(new Point(224,143));
		sections.add(points);
		line=new GuiLine(sections,Intr1.IMR6());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(98,134));
		points.add(new Point(189,134));
		points.add(new Point(189,143));
		sections.add(points);
		line=new GuiLine(sections,Intr1.IMR7());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(441,10));
		points.add(new Point(416,10));
		points.add(new Point(416,143));
		sections.add(points);
		line=new GuiLine(sections,Intr1.PRINTR1());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(441,31));
		points.add(new Point(381,31));
		points.add(new Point(381,143));
		sections.add(points);
		line=new GuiLine(sections,Intr1.PRINTR2());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(441,51));
		points.add(new Point(345,51));
		points.add(new Point(345,142));
		sections.add(points);
		line=new GuiLine(sections,Intr1.PRINTR3());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(441,72));
		points.add(new Point(310,73));
		points.add(new Point(310,144));
		sections.add(points);
		line=new GuiLine(sections,Intr1.PRINTR4());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(441,93));
		points.add(new Point(275,92));
		points.add(new Point(275,143));
		sections.add(points);
		line=new GuiLine(sections,Intr1.PRINTR5());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(441,113));
		points.add(new Point(239,113));
		points.add(new Point(239,143));
		sections.add(points);
		line=new GuiLine(sections,Intr1.PRINTR6());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(441,134));
		points.add(new Point(204,134));
		points.add(new Point(204,143));
		sections.add(points);
		line=new GuiLine(sections,Intr1.PRINTR7());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(409,176));
		points.add(new Point(409,370));
		points.add(new Point(371,370));
		points.add(new Point(371,425));
		sections.add(points);
		line=new GuiLine(sections,AND1.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(441,339));
		points.add(new Point(158,339));
		points.add(new Point(158,301));
		points.add(new Point(146,301));
		sections.add(points);
		line=new GuiLine(sections,AND1.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(373,176));
		points.add(new Point(373,360));
		points.add(new Point(350,360));
		points.add(new Point(350,425));
		sections.add(points);
		line=new GuiLine(sections,AND2.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(441,319));
		points.add(new Point(166,319));
		points.add(new Point(166,293));
		points.add(new Point(147,293));
		sections.add(points);
		line=new GuiLine(sections,AND2.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(338,176));
		points.add(new Point(338,350));
		points.add(new Point(330,350));
		points.add(new Point(330,426));
		sections.add(points);
		line=new GuiLine(sections,AND3.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(441,298));
		points.add(new Point(174,298));
		points.add(new Point(174,285));
		points.add(new Point(144,285));
		sections.add(points);
		line=new GuiLine(sections,AND3.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(302,176));
		points.add(new Point(302,350));
		points.add(new Point(310,350));
		points.add(new Point(310,426));
		sections.add(points);
		line=new GuiLine(sections,AND4.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(441,278));
		points.add(new Point(144,277));
		sections.add(points);
		line=new GuiLine(sections,AND4.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(267,176));
		points.add(new Point(268,360));
		points.add(new Point(290,360));
		points.add(new Point(290,426));
		sections.add(points);
		line=new GuiLine(sections,AND5.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(441,257));
		points.add(new Point(174,257));
		points.add(new Point(174,270));
		points.add(new Point(145,270));
		sections.add(points);
		line=new GuiLine(sections,AND5.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(232,176));
		points.add(new Point(232,370));
		points.add(new Point(270,370));
		points.add(new Point(270,426));
		sections.add(points);
		line=new GuiLine(sections,AND6.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(441,236));
		points.add(new Point(166,236));
		points.add(new Point(166,262));
		points.add(new Point(147,262));
		sections.add(points);
		line=new GuiLine(sections,AND6.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(196,176));
		points.add(new Point(196,381));
		points.add(new Point(249,381));
		points.add(new Point(249,426));
		sections.add(points);
		line=new GuiLine(sections,AND7.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(441,216));
		points.add(new Point(158,216));
		points.add(new Point(159,255));
		points.add(new Point(147,254));
		sections.add(points);
		line=new GuiLine(sections,AND7.getOut(0));
		gui.addLine(line);

		//
		//
		
		// 
		// 
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(115,278));
		points.add(new Point(105,278));
		points.add(new Point(105,355));
		points.add(new Point(96,355));
		sections.add(points);
		line=new GuiLine(sections,ORimrprintr.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(105,380));
		points.add(new Point(105,370));
		points.add(new Point(97,370));
		sections.add(points);
		line=new GuiLine(sections,Exec2.PSWI());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(149,492));
		points.add(new Point(149,362));
		points.add(new Point(97,362));
		sections.add(points);
		line=new GuiLine(sections,CMPintr.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(64,362));
		points.add(new Point(55,362));
		sections.add(points);
		line=new GuiLine(sections,ANDprintr.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(108,524));
		points.add(new Point(117,524));
		sections.add(points);
		line=new GuiLine(sections,Exec2.PSWL2());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(108,545));
		points.add(new Point(117,545));
		sections.add(points);
		line=new GuiLine(sections,Exec2.PSWL1());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(108,565));
		points.add(new Point(117,565));
		sections.add(points);
		line=new GuiLine(sections,Exec2.PSWL0());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(351,492));
		points.add(new Point(351,565));
		points.add(new Point(180,565));
		sections.add(points);
		line=new GuiLine(sections,CDintr.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(352,565));
		points.add(new Point(412,565));
		sections.add(points);
		line=new GuiLine(sections,CDintr.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(320,491));
		points.add(new Point(320,545));
		points.add(new Point(180,545));
		sections.add(points);
		line=new GuiLine(sections,CDintr.getOut(1));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(321,545));
		points.add(new Point(411,545));
		sections.add(points);
		line=new GuiLine(sections,CDintr.getOut(1));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(290,492));
		points.add(new Point(290,524));
		points.add(new Point(180,524));
		sections.add(points);
		line=new GuiLine(sections,CDintr.getOut(2));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(291,524));
		points.add(new Point(411,524));
		sections.add(points);
		line=new GuiLine(sections,CDintr.getOut(2));
		gui.addLine(line);

		//
		//


	}
	/////////////
	/////////////
	/////////////
	
	public static void init() {
		
		not_printr = new NOT();
		
		AND1 = new AND();
		AND2 = new AND();
		AND3 = new AND();
		AND4 = new AND();
		AND5 = new AND();
		AND6 = new AND();
		AND7 = new AND();
		ANDprintr = new AND(3);
		ORimrprintr = new OR(7);
		CDintr = new CD(8);
		CMPintr = new CMP(3);
	}
	
	public static void connect() {
		
		not_printr.setInputPin(0, ANDprintr.getOut(0));
		
		AND1.setInputPin(0, Intr1.IMR1());
		AND1.setInputPin(1, Intr1.PRINTR1());
		AND2.setInputPin(0, Intr1.IMR2());
		AND2.setInputPin(1, Intr1.PRINTR2());
		AND3.setInputPin(0, Intr1.IMR3());
		AND3.setInputPin(1, Intr1.PRINTR3());
		AND4.setInputPin(0, Intr1.IMR4());
		AND4.setInputPin(1, Intr1.PRINTR4());
		AND5.setInputPin(0, Intr1.IMR5());
		AND5.setInputPin(1, Intr1.PRINTR5());
		AND6.setInputPin(0, Intr1.IMR6());
		AND6.setInputPin(1, Intr1.PRINTR6());
		AND7.setInputPin(0, Intr1.IMR7());
		AND7.setInputPin(1, Intr1.PRINTR7());

		CDintr.setE(new Pin(true));
		CDintr.setInputPin(0, new Pin(false));
		CDintr.setInputPin(1, AND1.getOut(0));
		CDintr.setInputPin(2, AND2.getOut(0));
		CDintr.setInputPin(3, AND3.getOut(0));
		CDintr.setInputPin(4, AND4.getOut(0));
		CDintr.setInputPin(5, AND5.getOut(0));
		CDintr.setInputPin(6, AND6.getOut(0));
		CDintr.setInputPin(7, AND7.getOut(0));

		CMPintr.setE(new Pin(true));
		CMPintr.setPinA(0, CDintr.getOut(0));
		CMPintr.setPinA(1, CDintr.getOut(1));
		CMPintr.setPinA(2, CDintr.getOut(2));
		CMPintr.setPinB(0, Exec2.PSWL0());
		CMPintr.setPinB(1, Exec2.PSWL1());
		CMPintr.setPinB(2, Exec2.PSWL2());

		ORimrprintr.setInputPin(0, AND1.getOut(0));
		ORimrprintr.setInputPin(1, AND2.getOut(0));
		ORimrprintr.setInputPin(2, AND3.getOut(0));
		ORimrprintr.setInputPin(3, AND4.getOut(0));
		ORimrprintr.setInputPin(4, AND5.getOut(0));
		ORimrprintr.setInputPin(5, AND6.getOut(0));
		ORimrprintr.setInputPin(6, AND7.getOut(0));

		ANDprintr.setInputPin(0, ORimrprintr.getOut(0));
		ANDprintr.setInputPin(1, CMPintr.getOut(0));
		ANDprintr.setInputPin(2, Exec2.PSWI());

	}
	
	public static Pin irm1() {
		return AND1.getOut(0);
	}

	public static Pin irm2() {
		return AND2.getOut(0);
	}

	public static Pin irm3() {
		return AND3.getOut(0);
	}
	
	public static Pin irm4() {
		return AND4.getOut(0);
	}

	public static Pin irm5() {
		return AND5.getOut(0);
	}
	
	public static Pin irm6() {
		return AND6.getOut(0);
	}

	public static Pin irm7() {
		return AND7.getOut(0);
	}

	public static Pin prl0() {
		return CDintr.getOut(0);
	}

	public static Pin prl1() {
		return CDintr.getOut(1);
	}

	public static Pin prl2() {
		return CDintr.getOut(2);
	}

	public static Pin printr() {
		return ANDprintr.getOut(0);
	}
	
	public static Pin not_printr() {
		return not_printr.getOut(0);
	}

}
